package com.bwf.udp;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/26 10:36
 * @Copyright 博为峰
 */
public class UDPSendDemo02 {
    public static void main(String[] args) throws Exception {

        DatagramSocket ds = new DatagramSocket(6666);
        InputStream in = System.in;
        InputStreamReader inputStreamReader = new InputStreamReader(in);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            byte[] bytes = line.getBytes();
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("172.20.255.74"), 9999);
            ds.send(packet);
            if (line.equals("bye")) {
                break;
            }
        }
        ds.close();
    }
}
